package com.tianyu.model.ro;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;

/**********************************
 * @Author YSW
 * @Description 服务调用返回结果模板类
 * @Date 2021/2/25 - 14:47
 **********************************/

@Data
@Builder
@ToString
@AllArgsConstructor
@Accessors(chain = true)
public class ServiceRo<T>{
    private Boolean result;

    private Integer code;

    private String message;

    private T data;

    public ServiceRo() {
        this.result = true;
    }

    public ServiceRo<T> failureResult(String message) {
        this.result = false;
        this.message = message;
        return this;
    }

    public static ServiceRo<?> resultFailed(String message){
        return new ServiceRo<>().failureResult(message);
    }

    public static ServiceRo<?> resultSuccess(Object any){
        return new ServiceRo<>().setData(any);
    }
    public static ServiceRo<?> resultSuccess(){
        return new ServiceRo<>();
    }
}
